﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Users_MyOrderDetail : System.Web.UI.Page
{
    protected void Page_PreInit(object sender, EventArgs e)
    {
        Page.Theme = BLL.Common.GetWSThemes();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        Page.Title = BasePage.WebTitle;
        if (!HttpContext.Current.User.Identity.IsAuthenticated)
        {
            Response.Redirect("Login.aspx");
        }
        if (!IsPostBack)
        {
            GetOrderInfo();
            GetData();
            GetZFData();
            GetODNote();
        }
    }
    #region 订单主信息

    private void GetOrderInfo()
    {
        string orderid = Request.QueryString["OrderID"].ToString().Trim();
        Model.ORDERDOC od = new BLL.ORDERDOC().GetModel(orderid);
        lbl_OrderID.Text = od.ORDER_ID;
        lbl_OrderState.Text = BasePage.GetOrderState(od.ORDER_DELETE.ToString(), od.ORDER_LOCK.ToString(), od.ORDER_CHECK.ToString(), od.ORDER_ACHECK.ToString(), od.ORDER_SEND.ToString(), od.ORDER_HAVEPAYED.ToString(), od.ORDER_ID);
        lbl_OrderTime.Text = od.ORDER_CREATEDATE.ToString();
        lbl_Receiver.Text = od.ORDER_GETER;
        lbl_Address.Text = (new BLL.Province().GetModel(od.ORDER_PROVINCE).ProName) + (new BLL.City().GetModel(od.ORDER_CITY).CityName) + (new BLL.Area().GetModel(od.ORDER_AREA).AreaName) + od.ORDER_GETADDRESS;
        lbl_Phone.Text = od.ORDER_GETERPHONE1 + "\n" + od.ORDER_GETERPHONE2;
        Model.TRANER traner = new Model.TRANER();
        traner = new BLL.TRANER().GetModel(od.ORDER_TRANERCODE);
        lbl_Tran.Text = "物流方式:" + traner.TRANER_NAME;
        lbl_TranFY.Text = "物流费用:" + od.ORDER_TRANCOST.ToString("f");
        lbl_PAmt.Text = od.ORDER_AAMT.ToString("F2");
        lbl_Rangli.Text = od.ORDER_OFFERAMT.ToString("F2");
        lbl_Zhifu.Text = od.ORDER_AAMT.ToString("F2");
        lbl_Weight.Text = od.ORDER_WEIGHT.ToString("F0");
        lbl_BuyJF.Text = string.Format("{0:F}", od.ORDER_AAMT * BasePage.GetBaseBS());

    }
    #endregion

    #region 订单商品明细
    private void GetData()
    {
        string orderid = Request.QueryString["OrderID"].ToString().Trim();
        DataSet ds = new BLL.ORDERDETAIL().P_Order_GetProductMX(orderid);
        Repeater1.DataSource = ds.Tables[0].DefaultView;
        Repeater1.DataBind();
    }
    #endregion

    #region 订单支付明细
    private void GetZFData()
    {
        string orderid = Request.QueryString["OrderID"].ToString().Trim();
        DataSet ds = new BLL.PAYDETAIL().P_Order_GetProductZFMX(orderid);
        foreach (DataRow row in ds.Tables[0].Rows)
        {
            if (row["PD_PAYTYPE"].ToString() == "300" || row["PD_PAYTYPE"].ToString() == "301" || row["PD_PAYTYPE"].ToString() == "302")
            {
                Hid_Type.Value = row["PD_PAYTYPE"].ToString();
                Hidden1.Value = row["PD_PAYAMT"].ToString();
            }
        }
        if (Hid_Type.Value.Length > 0)
        {
            LinkButton1.Visible = true;
        }
        else
        {
            LinkButton1.Visible = false;
        }
        Repeater2.DataSource = ds.Tables[0].DefaultView;
        Repeater2.DataBind();
    }
    #endregion
    #region 订单意见信息
    private void GetODNote()
    {
        string orderid = Request.QueryString["OrderID"].ToString().Trim();
        DataSet ds = new BLL.ORDERNOTE().GetOrderNoteById(orderid);
        Repeater3.DataSource = ds.Tables[0];
        Repeater3.DataBind();
    }
    #endregion

    #region 继续支付
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        if (ConfigurationManager.AppSettings["ISPay"].ToString() == "1")
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('模拟版本,不提供此功能!')", true);
        }
        else
        {
            string type = Hid_Type.Value;
            string orderid = lbl_OrderID.Text.ToString();
            string money = Hidden1.Value;
            switch (type)
            {
                case "300": //支付宝                
                    AliPay.ToPay(orderid, money);
                    break;
                case "301": //网银在线                
                    Session["OrderId"] = orderid;
                    Session["v_amount"] = money;
                    Response.Redirect("../Pay/chinabank/Send.aspx");
                    break;
                case "302": //快钱                
                    Session["OrderId"] = orderid;
                    Session["v_amount"] = money;
                    Response.Redirect("../Pay/99bill/Send.aspx");
                    break;
            }
        }
    }
    #endregion
}
